﻿
Partial Class Public_WorkHeader_SearchWorkHeader
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.InitData()
        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub

    '編輯
    Protected Sub gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv.RowUpdating
        Me.CasePassword = Me.txtCasePassword.Text
        Dim key As DataKey = Me.gv.DataKeys(e.RowIndex)
        Me.FindDirtyHeaderID = key("FindDirtyHeaderID")
        RaiseEvent RowUpdating(Me, New EventArgs)
    End Sub
    '刪除
    Protected Sub gv_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gv.RowDeleting
        Dim key As DataKey = Me.gv.DataKeys(e.RowIndex)
        Me.FindDirtyHeaderID = key("FindDirtyHeaderID")
        RaiseEvent RowDeleting(Me, New EventArgs)
    End Sub

    Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            'TryCast(e.Row.FindControl("lknDelete"), LinkButton).Enabled = IIf(DataBinder.Eval(e.Row.DataItem, "Status") = "1", True, False)
        End If
    End Sub
End Class

Partial Class Public_WorkHeader_SearchWorkHeader
#Region "初始化資料"
    Private Sub InitData()

    End Sub
#End Region

#Region "繫結資料"
    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select a.*,b.RegionName+a.Location as Address,c.Text as StatusText from FD_FindDirtyHeader a")
        sql.AppendFormat(" inner Join Region b on a.TownID=b.RegionID and b.RegionType='T'")
        sql.AppendFormat(" left Join FD_CodeMapping c on a.Status=c.Value and c.TableName='FindDirtyHeader' and c.ColumnName='Status' and c.Active='Y'")
        sql.AppendFormat(" where a.RandomCasePassword = '{0}' ", Me.txtCasePassword.Text.Trim())
        sql.AppendFormat(" and a.Active='Y'")
        sql.AppendFormat(" order by a.ReportDate desc")
        dt = dat.GetData(sql)
        MyObj.SetDateLocale("zh-TW")
        Me.gv.DataSource = dt
        Me.gv.DataBind()
        MyObj.SetDateLocale("")
        RaiseEvent DataBound(Me, New EventArgs)
        Me.gv.SelectedIndex = -1
        If dt.Rows.Count = 0 Then
            MyObj.ShowMessage(Me.GetLocalResourceObject("NoData"))
        End If
    End Sub

    Public Sub BindGV(ByVal MyCasePassword As String)
        Me.txtCasePassword.Text = MyCasePassword
        Me.BindGV()

        Me.CasePassword = Me.txtCasePassword.Text
        If Me.gv.Rows.Count > 0 Then
            Dim key As DataKey = Me.gv.DataKeys(0)
            Me.FindDirtyHeaderID = key("FindDirtyHeaderID")
        End If
    End Sub

#End Region

#Region "屬性"
    Public Property CasePassword() As String
        Get
            Return ViewState("CasePassword")
        End Get
        Set(ByVal value As String)
            ViewState("CasePassword") = value
        End Set
    End Property

    Public Property FindDirtyHeaderID() As String
        Get
            Return ViewState("FindDirtyHeaderID")
        End Get
        Set(ByVal value As String)
            ViewState("FindDirtyHeaderID") = value
        End Set
    End Property

    Public ReadOnly Property Count() As Integer
        Get
            Return Me.gv.Rows.Count
        End Get
    End Property
#End Region

#Region "事件"
    Public Event RowUpdating(ByVal source As Object, ByVal e As EventArgs)
    Public Event RowDeleting(ByVal source As Object, ByVal e As EventArgs)
    Public Event DataBound(ByVal source As Object, ByVal e As EventArgs)
#End Region
End Class